jQuery(function(){
  var $news   = jQuery('.widget.loliNews');
  
  if($news.length>0){
    var $viewer = jQuery('.viewer',$news);
    if  ($viewer.length==1){
      $news.delegate('a.suite','click',function(event){
        event.stopPropagation();
        event.cancelBubble=true;
        var $this = jQuery(this);
        var $detail = $this.closest('.detail');
        var diff = $detail.attr('loli-diff');
        $detail.find('.text').animate({'max-height':'+='+diff});
        $this.hide(200,function(){
          $this.removeClass('has-more');
        });
        return false;
      });
    }
  }
  
  // présentation et lire la suite
  jQuery('.more',$news).each(function(){
    var $suite = jQuery(this);
    var $parent = $suite.parent();
    var pos1 = $suite.position();
    var pos2 = $parent.position();
    var diff = (pos1.top+$suite.height()) - (pos2.top+$parent.height());
    
    if(diff>0){
      $parent.closest('.detail').addClass('has-more').attr('loli-diff',diff);
    }
    
  });

  
});
